﻿using System.Collections.Generic;
using ServiceManager.Utils;
namespace QuotationService.RealtimeQuotation
{
    public abstract class QuotationRepositoryBase
    {
        private static MarketInfoConverter marketInfoConverter = new MarketInfoConverter();

        #region 市场信息操作
        /// <summary>
        /// 更新市场信息
        /// </summary>
        /// <param name="quotSource"></param>
        /// <param name="marketInfo"></param>
        /// <returns></returns>
        public static bool UpdateMarketInfo(string quotSource, Quotation.MarketInfo marketInfo)
        {
            var marketInfoEntity = marketInfoConverter.Convert(marketInfo);
            byte[] bytes = marketInfoEntity.StructToBytes<MarketInfo>();
            return MarketInfoChannel.Update(quotSource, bytes);
        }
        /// <summary>
        /// 获取市场信息
        /// </summary>
        /// <param name="quotSource"></param>
        /// <returns></returns>
        public static Quotation.MarketInfo GetMarketInfo(string quotSource)
        {
            byte[] bytes = MarketInfoChannel.Get(quotSource);
            if (bytes != null)
            {
                MarketInfo marketInfo = StructHelper.BytesToStruct<MarketInfo>(bytes);
                return marketInfoConverter.Convert(marketInfo);
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 清除市场信息
        /// </summary>
        /// <param name="quotSource"></param>
        /// <returns></returns>
        public static bool ClearMarketInfo(string quotSource)
        {
            return MarketInfoChannel.Clear(quotSource);
        }
        #endregion

        #region 取全部代码
        public static List<string> GetAllCodes(string quotSouce)
        {
            return BasicInfoChannel.GetAllCodes(quotSouce);
        }
        #endregion

    }
}
